<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Class D_Controller extends CI_Controller{

	public function __construct(){
		parent::__construct();

		$this->load->model('sys/sys_config');
		$this->load->model('fnd/fnd_languages');

		$this->load_sys_config();
		$this->init_session();
		$this->inti_language();

		if(!defined('TEMPLATES')){
			define('TEMPLATES', 'default');
		}

		//初始化模板
		$this->load->add_view_path(TEMPLATES);
	}

	/**
	 * 初始化系统配置
	 * @return null
	 */
	private function load_sys_config(){
		$configs = $this->sys_config->get_sys_config();
		while (list(, $row) = each($configs)) {
			if(!defined($row['config_key'])){
				define($row['config_key'], $row['config_value']);
			}else{
				log_message('debugger', $row['config_key'].'已定义!');
			}
		}
	}

	/**
	 * 初始化session
	 * @return null
	 */
	private function init_session(){
		//初始化语言
		$languages = $this->fnd_languages->get_default_lang();
		if(!$languages){
			show_error('No language has defined!');
		}
		$this->session->set_userdata($languages);
		$this->config->set_item('language',$languages['language_folder']);

		//var_dump($this->session->all_userdata());
	}

	/**
	 * 加载多语言
	 */
	private function inti_language(){
		$controller = $this->uri->rsegment(1);
		$this->lang->load($controller);
	}
}

// END MY_Controller Class

/* End of file Log.php */
/* Location: ./system/libraries/Log.php */